#include <fstream>
#include "Newton.h"
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{


  double n=7;
  double a[7] = {0,6,10,13,17,20,28};
  double b[7] = {6.67,17.3,42.7,37.3,30.1,29.3,28.7};
  double c[7] = {6.67,16.1,18.9,15.0,10.6,9.44,8.89};
  vector<double> x;
  vector<double> y1;
  vector<double> y2;
  for (int i=0; i<7; i++)
    {
      x.push_back(a[i]);
      y1.push_back(b[i]);
      y2.push_back(c[i]);
    }

 Newton problem_e1(x,y1);
 Newton problem_e2(x,y2);
 /*for(int i=0;i<x.size();i++){
 cout<<"x^("<<n-1-i<<"): "<<problem_e1.anwser[i]<<endl;
 }

  for(int i=0;i<x.size();i++){
 cout<<"x^("<<n-1-i<<"): "<<problem_e2.anwser[i]<<endl;
 }
 */

 double t=43;
 double weight1=0;
 double weight2=0;
 n=x.size();
 for(int i=0;i<n;i++){
   weight1=weight1+pow(t,n-1-i)*problem_e1.answer[i];
 }
  for(int i=0;i<n;i++){
   weight2=weight2+pow(t,n-1-i)*problem_e2.answer[i];
 }
  if (weight1<=6.67)
     cout<<"SP1 will die."<<endl;
  else
     cout<<"SP1 will not die."<<endl;
  if (weight2<=6.67)
     cout<<"SP2 will die."<<endl;
  else
     cout<<"SP2 will not die."<<endl;


  
   ofstream p_E1;
     p_E1.open("p_E1.txt", std::ios::out);
     //p_E1.open("p_E1.txt", std::ios::out | std::ios::app);  
       if (!p_E1.is_open())
        return 0;
            for(int i=0;i<x.size();i++)
	      {
               p_E1<< problem_e1.answer[i] <<endl;
              }

	      p_E1.close();

   ofstream p_E2;
     p_E2.open("p_E2.txt", std::ios::out);
     //p_E2.open("p_E2.txt", std::ios::out | std::ios::app);  
       if (!p_E2.is_open())
        return 0;
            for(int i=0;i<x.size();i++)
	      {
               p_E2<< problem_e2.answer[i] <<endl;
              }

	      p_E2.close();

}
